package com.lyf.scm.plan.domain.repository;

import com.lyf.scm.plan.api.dto.RolePermissionsDTO;
import com.lyf.scm.plan.domain.convertor.RolePermissionsConvertor;
import com.lyf.scm.plan.insfrastructure.db.mapper.RolePermissionsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * description:
 * 角色权限
 *
 * @author: haodong
 * @data: 2020/8/20 13:46
 */
@Service
public class RolePermissionsRepository {
    @Resource
    private RolePermissionsConvertor rolePermissionsConvertor;

    @Resource
    private RolePermissionsMapper rolePermissionsMapper;


    /**
     * 根据level等级查询权限信息
     *
     * @param level
     * @return
     */
    public RolePermissionsDTO getPermissionByLevel(Integer level) {
        return rolePermissionsConvertor.doToDTO(rolePermissionsMapper.getPermissionByLevel(level));
    }

    /**
     * 获取最高权限等级
     *
     * @return
     */
    public Integer getMaxLevel() {
        return rolePermissionsMapper.getMaxLevel();
    }

    /**
     * 获取最低权限等级
     *
     * @return
     */
    public Integer getMinLevel() {
        return rolePermissionsMapper.getMinLevel();
    }

    /**
     * 根据id查询权限级别
     * @param id
     * @return
     */
    public RolePermissionsDTO getPermissionById(Long id) {
        return rolePermissionsConvertor.doToDTO(rolePermissionsMapper.getPermissionById(id));
    }
}
